﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using

using System;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using NetBay.Core.DataAccess;
using NetBay.Core.Extensions;

#endregion

namespace Rio.Framework.RioManager
{
    /// <summary>
    /// Classe to handle datas from DB
    /// </summary>
    public static class DA_Settings
    {
        #region Enum
        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        private enum DbFunction
        {
            [DescriptionAttribute("")]
            None = 0,
            [DescriptionAttribute("P_GeneralSettings_list")]
            GetGeneralSettings,
        }
        #endregion

        #region Functions

        #region Publics
        /// <summary>
        /// Load Settings From DB
        /// </summary>
        /// <param name="p_sPackageName">Package name (it's spécific for Oracle DB)</param>
        /// <remarks>packageName is optional. Don't forget the dot character at the end</remarks>
        /// <returns>Return a IDataReader with all settings values</returns>
        public static IDataReader Load(string p_sPackageName)
        {
            try
            {
                var db = DbHelper.DataBase;

                var l_bOutPutParameter = false;

                if (p_sPackageName.Equals("RIO.BDD.Oracle"))
                   l_bOutPutParameter = true;

                var dbCommand = db.GetStoredProcCommand(DbFunction.GetGeneralSettings.szGetDescription());


                if (l_bOutPutParameter)
                {
                    var l_oOracleOutputParameter = new OracleParameter("O_Results", OracleType.Cursor);
                    l_oOracleOutputParameter.Direction = ParameterDirection.Output;
                    dbCommand.Parameters.Add(l_oOracleOutputParameter);
                }


                return db.ExecuteReader(dbCommand);
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("() EXCEPTION -> " + Environment.NewLine + ex);
            }

            return null;
        }
        #endregion

        #region Privates
        #endregion

        #endregion
    }
}